<?php
/**
 * Created by PhpStorm.
 * User: xiaofeng
 * motto: 现在的努力是为了小时候吹过的牛逼！
 * Date: 2020/9/21
 * Time: 22:51
 */
namespace app\common\business;
use app\common\model\mysql\GoodsSku as GoodsSkuModel;
class GoodsSku extends BusBase{
    public $model = null;

    public function __construct()
    {
        $this->model = new GoodsSkuModel();
    }

    /**
     * 批量新增逻辑
     * @param $data
     */
    public function saveAll($data){
        if (!$data['skus']){
            return false;
        }
        foreach ($data['skus'] as $value){
            $insertData[] = [
                "goods_id"=>$data['goods_id'],
                "specs_value_ids"=>$value['propvalnames']['propvalids'],
                "price"=>$value['propvalnames']['skuSellPrice'],
                "cost_price"=>$value['propvalnames']['skuMarketPrice'],
                "stock"=>$value['propvalnames']['skuStock']
            ];
        }
        try{
            $result = $this->model->saveAll($insertData);
            return $result->toArray();
        }catch (\Exception $e){
            // 记录日志
            return false;
        }
        return true;
    }
}
